package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.entity.Appraise;
import com.hl.sfzy.service.AppraiseService;
import com.hl.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 1. @ClassDescription:
 * 2. @ClassName AppraiseController
 * 3. @Description TODO
 * 4. @Author: YuKunXu
 * 5. @Date: 2024年01月15日 17:22
 * 6. @Project: sfzy
 * 7. @Version 1.0
 */
@CrossOrigin
@RestController
@RequestMapping("/appraise")
public class AppraiseController {
    @Autowired
    private AppraiseService appraiseService;
    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody Appraise appraise) throws Exception {
        appraiseService.add(appraise);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Integer id) {
        appraiseService.remove(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/remove")
    public Result removeBatch(Integer[] ids) {
        System.out.println(ids);
        appraiseService.removeBatch(ids);
        return Result.success();
    }

    /**
     * 分页查询
     */
    @GetMapping("/find")
    public Result findPage(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
                                             @RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
                                             Appraise appraise) {
        return Result.success(appraiseService.findPage(pageNum, pageSize, appraise));
    }
}